package ejb;

import mode.Sex;
import model.entity.Appartment;
import model.entity.Person;

import javax.annotation.sql.DataSourceDefinition;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import java.util.Calendar;

/**
 * Created with IntelliJ IDEA.
 * User: ashishov
 * Date: 4/10/13
 * Time: 7:40 PM
 * To change this template use File | Settings | File Templates.
 */
@Stateless
@DataSourceDefinition(
        name = "java:env/MyApp/MyDataSource",
        className = "com.mysql.jdbc.jdbc2.optional.MysqlDataSource",
        url = "jdbc:mysql://localhost:33306/JPA",
        user = "root",
        password = "11111"
)
public class DbBean {

    @PersistenceUnit(unitName = "PersistenceService")
    EntityManagerFactory emf;

    public void doStuff(){
        EntityManager em = emf.createEntityManager();

        Appartment ap = new Appartment();
        //ap.setId(1);
        //ap.setAddress("ssss");
        //em.persist(ap);
        //em.flush();
        Appartment a = em.find(Appartment.class, 1);

        Person p = new Person();
        p.setSex(Sex.FEMALE);
        p.setBirthDay(Calendar.getInstance().getTime());
        em.persist(p);

        return;

    }
}
